<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { showToast } from 'vant';
import { useAddressStore } from '../../stores/address';

const addressStore = useAddressStore();
const router = useRouter();



// 点击新增按钮
const onAdd = () => showToast('新增地址',
    router.back()
);


const onEdit = (item, index) => {
    router.push({
        path:'/address/edit', 
        query: {
            id: item.id
        }
    })
}


// 切换地址 跳转首页
const onSelect = () => showToast('切换地址',
    router.back()
);



</script>

<template>
   <div class="page">
    <van-address-list
        v-model="addressStore.chosenAddressId"
        :list="addressStore.addressList"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="onSelect"
    />
   </div>


</template>

<style lang="scss" scoped>
.page{
    background: #eeeeee;
    height: 100vh;
}
</style>